// 存储领料单的状态筛选和关键字搜索
import consts from "@/utils/consts";

const inProcessKey = 'inProcess'

const state = {
    requisitionState: 0,
    requisitionKeywords: '',
    inProcess: JSON.parse(localStorage.getItem(inProcessKey)) || [],
};

const getters = {
    requisitionState: (state) => state.requisitionState || consts.allState,
    requisitionKeywords: (state) => state.requisitionKeywords,
    inProcess: (state) => state.inProcess,
}

const actions = {

}

const mutations = {
    setRequisitionState: (state, status) => state.requisitionState = status,
    setRequisitionKeywords: (state, keywords) => state.requisitionKeywords = keywords,
    addInProcess: (state, outStock) => {
        if (state.inProcess.indexOf(outStock) == -1) {
            state.inProcess.push(outStock)
            console.log(state.inProcess);
            localStorage.setItem(inProcessKey, JSON.stringify(state.inProcess))
        }
    },
    removeInProcess: (state, outStock) => {
        const index = state.inProcess.indexOf(outStock);
        if (index != -1) {
            state.inProcess.splice(index, 1);
            console.log(state.inProcess);
            localStorage.setItem(inProcessKey, JSON.stringify(state.inProcess))
        }
    }
}

export default {
    state,
    getters,
    actions,
    mutations
}